﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;
using Cashier_DAO.db;
using System.Collections;

namespace Cashier_DAO
{
    public class ChinacityDAO: DAOFactory
    {
        /// <summary>
        /// 查询省市信息
        /// </summary>
        /// <param name="conn"></param>
        /// <param name="parent"></param>
        /// <returns></returns>
        public DataTable GetChinacityTable(DbConnection conn, String parent)
        {
            DataTable dt = null;
            try
            {
                StringBuilder sql = new StringBuilder("select * from dic_chinacity");               
                if (!String.IsNullOrEmpty(parent))
                {
                    sql.Append(" where parent=@parent");
                }
                sql.Append(" order by id asc");
                DbCommand cmd = CommandFactory.CreateCommand(sql.ToString(), conn);
                Hashtable paramtable = new Hashtable();
                if (!String.IsNullOrEmpty(parent))
                {
                    paramtable.Add("parent", parent);
                    this.AddCommandParamters(cmd, paramtable);
                }
                DbDataAdapter da = DataAdapterFactory.CreateDataAdapter(cmd);
                dt = new DataTable("chinacity");
                da.Fill(dt);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }
    }
}
